home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / MPW / gzip 1.2.2 / cextras-1.0 / testdir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-11  |  943 b   |  55 lines  |  [TEXT/MPS ]

  1. /*
  2.     testdir -- basic test for C library directory access routines
  3.  
  4.     last edit:    25-Apr-1987    D A Gwyn
  5. */
  6.  
  7. #include    <string.h>
  8. #include    <stdlib.h>
  9. #include    <stdio.h>
  10. #include    "dirent.h"
  11.  
  12. main( argc, argv )
  13.     int            argc;
  14.     register char        **argv;
  15. {
  16.     extern int        errno;
  17.     register DIR        *dirp;
  18.     register struct dirent    *dp;
  19.     int            nerrs = 0;    /* total not found */
  20.  
  21.     if ( (dirp = opendir( ":" )) == NULL )    /* ACA--changed "." to ":" for
  22.                            MacOS. 7-93 */
  23.         {
  24.         (void)fprintf( stderr, "Cannot open \":\" directory\n" );
  25.         exit( 1 );
  26.         }
  27.  
  28.     while ( --argc > 0 )
  29.         {
  30.         ++argv;
  31.  
  32.         while ( (dp = readdir( dirp )) != NULL )
  33.             {
  34.             if ( strcmp( dp->d_name, *argv ) == 0 )
  35.                 {
  36.                 (void)fprintf( stderr, "\"%s\" found.\n", *argv );
  37.                 break;
  38.                 }
  39.             }
  40.  
  41.         if ( dp == NULL )
  42.             {
  43.             if (errno)
  44.                 perror("");
  45.             (void)fprintf( stderr, "\"%s\" not found.\n", *argv );
  46.             ++nerrs;
  47.             }
  48.  
  49.         rewinddir( dirp );
  50.         }
  51.  
  52.     (void)closedir( dirp );
  53.     exit( nerrs );
  54. }
  55.